home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / MacOS 8 Resources / Developer Tools / Mac OS 8 Interfaces & Libraries / Interfaces / CIncludes / NumberFormatting.h < prev    next >
C/C++ Source or Header  |  1996-05-01  |  13KB  |  332 lines

  1. /*
  2.      File:        NumberFormatting.h
  3.  
  4.      Version:    Technology:    8.0
  5.                  Release:    Universal Interfaces 3.0d3 on Copland DR1
  6.  
  7.      Copyright:    © 1984-1996 by Apple Computer, Inc.  All rights reserved.
  8.  
  9.      Bugs?:        If you find a problem with this file, send the file and version
  10.                  information (from above) and the problem description to:
  11.  
  12.                      Internet:    apple.bugs@applelink.apple.com
  13.                      AppleLink:    APPLE.BUGS
  14.  
  15. */
  16. #ifndef __NUMBERFORMATTING__
  17. #define __NUMBERFORMATTING__
  18.  
  19. #ifndef __CONDITIONALMACROS__
  20. #include <ConditionalMacros.h>
  21. #endif
  22. #ifndef __TYPES__
  23. #include <Types.h>
  24. #endif
  25. #if FOR_SYSTEM8_PREEMPTIVE
  26. #ifndef __TEXTOBJECTS__
  27. #include <TextObjects.h>
  28. #endif
  29. #ifndef __TEXTCOMMON__
  30. #include <TextCommon.h>
  31. #endif
  32. #ifndef __LOCALEOBJECTS__
  33. #include <LocaleObjects.h>
  34. #endif
  35. #ifndef __TEXTPARSER__
  36. #include <TextParser.h>
  37. #endif
  38. #endif
  39. #if FOR_SYSTEM7_AND_SYSTEM8_COOPERATIVE
  40. #ifndef __INTLRESOURCES__
  41. #include <IntlResources.h>
  42. #endif
  43. #endif
  44.  
  45. #ifdef __cplusplus
  46. extern "C" {
  47. #endif
  48.  
  49. #if PRAGMA_IMPORT_SUPPORTED
  50. #pragma import on
  51. #endif
  52.  
  53. #if PRAGMA_ALIGN_SUPPORTED
  54. #pragma options align=mac68k
  55. #endif
  56.  
  57. /*
  58.  
  59.     Here are the current System 7 routine names and the translations to the older forms.
  60.     Please use the newer forms in all new code and migrate the older names out of existing
  61.     code as maintainance permits.
  62.     
  63.     New Name                    Old Name(s)
  64.     
  65.     ExtendedToString            FormatX2Str
  66.     FormatRecToString            Format2Str
  67.     NumToString                
  68.     StringToExtended            FormatStr2X
  69.     StringToFormatRec            Str2Format
  70.     StringToNum                
  71.  
  72. */
  73. #if FOR_SYSTEM7_AND_SYSTEM8_PREEMPTIVE
  74. struct NumFormatString {
  75.     UInt8                             fLength;
  76.     UInt8                             fVersion;
  77.     char                             data[254];                    /* private data */
  78. };
  79. typedef struct NumFormatString NumFormatString;
  80.  
  81. typedef NumFormatString NumFormatStringRec;
  82. #endif
  83. #if FOR_SYSTEM7_AND_SYSTEM8_COOPERATIVE
  84. typedef short FormatStatus;
  85.  
  86. enum {
  87.     fVNumber                    = 0                                /* first version of NumFormatString */
  88. };
  89.  
  90. typedef SInt8 FormatClass;
  91.  
  92. enum {
  93.     fPositive                    = 0,
  94.     fNegative                    = 1,
  95.     fZero                        = 2
  96. };
  97.  
  98. typedef SInt8 FormatResultType;
  99.  
  100. enum {
  101.     fFormatOK                    = 0,
  102.     fBestGuess                    = 1,
  103.     fOutOfSynch                    = 2,
  104.     fSpuriousChars                = 3,
  105.     fMissingDelimiter            = 4,
  106.     fExtraDecimal                = 5,
  107.     fMissingLiteral                = 6,
  108.     fExtraExp                    = 7,
  109.     fFormatOverflow                = 8,
  110.     fFormStrIsNAN                = 9,
  111.     fBadPartsTable                = 10,
  112.     fExtraPercent                = 11,
  113.     fExtraSeparator                = 12,
  114.     fEmptyFormatString            = 13
  115. };
  116.  
  117. struct FVector {
  118.     short                             start;
  119.     short                             length;
  120. };
  121. typedef struct FVector FVector;
  122.  
  123. /* index by [fPositive..fZero] */
  124. typedef FVector TripleInt[3];
  125. #if CGLUESUPPORTED
  126. extern void stringtonum(const char *theString, long *theNum);
  127.  
  128. extern void numtostring(long theNum, char *theString);
  129.  
  130. #endif
  131. /* CGLUESUPPORTED*/
  132. #endif
  133. #if FOR_SYSTEM7_AND_SYSTEM8_PREEMPTIVE
  134. extern pascal void StringToNum(ConstStr255Param theString, long *theNum);
  135.  
  136. extern pascal void NumToString(long theNum, Str255 theString);
  137.  
  138. #endif
  139. #if FOR_SYSTEM7_AND_SYSTEM8_COOPERATIVE
  140. extern pascal FormatStatus ExtendedToString(extended80 *x, const NumFormatString *myCanonical, const NumberParts *partsTable, Str255 outString)
  141.  FOURWORDINLINE(0x2F3C, 0x8210, 0xFFE8, 0xA8B5);
  142.  
  143. extern pascal FormatStatus StringToExtended(ConstStr255Param source, const NumFormatString *myCanonical, const NumberParts *partsTable, extended80 *x)
  144.  FOURWORDINLINE(0x2F3C, 0x8210, 0xFFE6, 0xA8B5);
  145.  
  146. extern pascal FormatStatus StringToFormatRec(ConstStr255Param inString, const NumberParts *partsTable, NumFormatString *outString)
  147.  FOURWORDINLINE(0x2F3C, 0x820C, 0xFFEC, 0xA8B5);
  148.  
  149. extern pascal FormatStatus FormatRecToString(const NumFormatString *myCanonical, const NumberParts *partsTable, Str255 outString, TripleInt positions)
  150.  FOURWORDINLINE(0x2F3C, 0x8210, 0xFFEA, 0xA8B5);
  151.  
  152. #endif
  153. #if OLDROUTINENAMES
  154. #if FOR_SYSTEM7_AND_SYSTEM8_DEPRECATED
  155. #define FormatX2Str(x, myCanonical, partsTable, outString)  \
  156.          ExtendedToString( x, myCanonical, partsTable, outString)
  157. #define FormatStr2X(source, myCanonical, partsTable, x)  \
  158.          StringToExtended( source, myCanonical, partsTable, x)
  159. #define Str2Format(inString, partsTable, outString)  \
  160.          StringToFormatRec(inString, partsTable, outString)
  161. #define Format2Str(myCanonical, partsTable, outString, positions)  \
  162.          FormatRecToString(myCanonical, partsTable, outString, positions)
  163. #endif
  164. /* FOR_SYSTEM7_AND_SYSTEM8_DEPRECATED*/
  165. #endif
  166. /* OLDROUTINENAMES*/
  167. #if FOR_SYSTEM8_PREEMPTIVE
  168. typedef LocaleObjectRef LocaleNumberFormatterObjectRef;
  169. typedef OptionBits NumberFormatterOptionBits;
  170. typedef UInt32 NumberFormatterTokenID;
  171. struct FIndexVector {
  172.     TextObjectIndex                 startIndex;
  173.     TextObjectIndex                 endIndex;
  174. };
  175. typedef struct FIndexVector FIndexVector;
  176.  
  177. /* index by [fPositive..fZero] */
  178. typedef FIndexVector TripleIndex[3];
  179. #define kNumberFormattingLocaleKeyName            "\pnumberformattable"
  180.  
  181. enum {
  182.                                                                 /*NumberFormatterOptionBits*/
  183.     kDontUseThousandSeparatorBit = 0,
  184.     kIsScientificFormatBit        = 1,
  185.     kIsPercentageFormatBit        = 2,
  186.     kIsCurrencyFormatBit        = 3,
  187.     kIsFractionCurrencyFormatBit = 4,
  188.     kIsLongFormCurrencyFormatBit = 5,
  189.     kOmitDecimalPointInCurrencyFormatBit = 6,
  190.     kUseAsciiDigitBit            = 7,
  191.     kUseNegativePosfixPrefixBit    = 8
  192. };
  193.  
  194.  
  195. enum {
  196.                                                                 /*NumberFormatterOptionBits*/
  197.     kStandardFormatMask            = 0,
  198.     kDontUseThousandSeparatorMask = 1L << kDontUseThousandSeparatorBit,
  199.     kIsScientificFormatMask        = 1L << kIsScientificFormatBit,
  200.     kIsPercentageFormatMask        = 1L << kIsPercentageFormatBit,
  201.     kIsCurrencyFormatMask        = 1L << kIsCurrencyFormatBit,
  202.     kIsFractionCurrencyFormatMask = 1L << kIsFractionCurrencyFormatBit,
  203.     kIsLongFormCurrencyFormatMask = 1L << kIsLongFormCurrencyFormatBit,
  204.     kOmitDecimalPointInCurrencyFormatMask = 1L << kOmitDecimalPointInCurrencyFormatBit,
  205.     kUseAsciiDigitMask            = 1L << kUseAsciiDigitBit,
  206.     kUseNegativePosfixPrefixMask = 1L << kUseNegativePosfixPrefixBit
  207. };
  208.  
  209. extern OSStatus GetNumberFormatterObjectFromRef(LocaleRef locale, LocaleNumberFormatterObjectRef *numberFormatterObject);
  210.  
  211. extern OSStatus GetNumberFormatterObjectFromID(LocaleIdentifier localeID, LocaleNumberFormatterObjectRef *numberFormatterObject);
  212.  
  213. extern OSStatus GetCurrentNumberFormatterObject(LocaleNumberFormatterObjectRef *numberFormatterObject);
  214.  
  215. extern OSStatus GetNumberFormatterObjectInfo(LocaleNumberFormatterObjectRef numberFormatterObject, TextEncoding *theEncoding, LocaleIdentifier *theLocaleIdentifier);
  216.  
  217. extern OSStatus ConvertUInt32ToTextObject(UInt32 theUInt32, LocaleNumberFormatterObjectRef numberFormatterObject, NumberFormatterOptionBits options, TextObject theTextObject, TextObjectIndex startReplaceIndex, TextObjectIndex endReplaceIndex);
  218.  
  219. extern OSStatus ConvertSInt32ToTextObject(SInt32 theSInt32, LocaleNumberFormatterObjectRef numberFormatterObject, NumberFormatterOptionBits options, TextObject theTextObject, TextObjectIndex startReplaceIndex, TextObjectIndex endReplaceIndex);
  220.  
  221. extern OSStatus ConvertUInt64ToTextObject(UInt64 theUInt64, LocaleNumberFormatterObjectRef numberFormatterObject, NumberFormatterOptionBits options, TextObject theTextObject, TextObjectIndex startReplaceIndex, TextObjectIndex endReplaceIndex);
  222.  
  223. extern OSStatus ConvertSInt64ToTextObject(SInt64 theSInt64, LocaleNumberFormatterObjectRef numberFormatterObject, NumberFormatterOptionBits options, TextObject theTextObject, TextObjectIndex startReplaceIndex, TextObjectIndex endReplaceIndex);
  224.  
  225. extern OSStatus ConvertDoubleToTextObject(double theDouble, LocaleNumberFormatterObjectRef numberFormatterObject, NumberFormatterOptionBits options, SInt8 precision, TextObject theTextObj, TextObjectIndex startReplaceIndex, TextObjectIndex endReplaceIndex);
  226.  
  227. extern OSStatus ConvertTextObjectToUInt32(ConstTextObject textObject, LocaleNumberFormatterObjectRef numberFormatterObject, NumberFormatterOptionBits options, TextObjectIndex startIndex, TextObjectIndex endIndex, UInt32 *theUInt32);
  228.  
  229. extern OSStatus ConvertTextObjectToSInt32(ConstTextObject textObject, LocaleNumberFormatterObjectRef numberFormatterObject, NumberFormatterOptionBits options, TextObjectIndex startIndex, TextObjectIndex endIndex, SInt32 *theSInt32);
  230.  
  231. extern OSStatus ConvertTextObjectToUInt64(ConstTextObject textObject, LocaleNumberFormatterObjectRef numberFormatterObject, NumberFormatterOptionBits options, TextObjectIndex startIndex, TextObjectIndex endIndex, UInt64 *theUInt64);
  232.  
  233. extern OSStatus ConvertTextObjectToSInt64(ConstTextObject textObject, LocaleNumberFormatterObjectRef numberFormatterObject, NumberFormatterOptionBits options, TextObjectIndex startIndex, TextObjectIndex endIndex, SInt64 *theSInt64);
  234.  
  235. extern OSStatus ConvertTextObjectToDouble(ConstTextObject textObject, LocaleNumberFormatterObjectRef localeObjectRef, TextObjectIndex startIndex, TextObjectIndex endIndex, double *theDouble);
  236.  
  237. extern OSStatus FormattedTextObjectToDouble(ConstTextObject textObject, LocaleNumberFormatterObjectRef ref, TextObjectIndex startIndex, TextObjectIndex endIndex, const NumFormatString *myCanonical, const double *num);
  238.  
  239. extern OSStatus DoubleToFormattedTextObject(double *num, LocaleNumberFormatterObjectRef ref, const NumFormatString *myCanonical, TextObject outTextObject);
  240.  
  241. extern OSStatus TextObjectToFormatRec(ConstTextObject textObject, LocaleNumberFormatterObjectRef ref, TextObjectIndex startIndex, TextObjectIndex endIndex, NumFormatString *outString);
  242.  
  243. extern OSStatus FormatRecToTextObject(const NumFormatString *myCanonical, LocaleNumberFormatterObjectRef ref, TextObject outTextObject, TripleIndex positions);
  244.  
  245.  
  246. enum {
  247.                                                                 /* NumberFormatterTokenID*/
  248.     kNumFmtCharLeftQuote        = 0,                            /*(begin literal)*/
  249.     kNumFmtCharRightQuote        = 1,                            /*(end literal)*/
  250.     kNumFmtCharLeadPlacer        = 2,                            /* (`^' in U.S)*/
  251.     kNumFmtCharLeader            = 3,                            /*(non-breakable space in U.S)*/
  252.     kNumFmtCharNonLeader        = 4,                            /*(# sign in U.S)*/
  253.     kNumFmtCharZeroLead            = 5,                            /*(digit `0' in U.S)*/
  254.     kNumFmtCharCurrencyPlacer    = 6,                            /* (`$' in U.S)*/
  255.     kNumFmtCharPercent            = 7,                            /* (`%') */
  256.     kNumFmtCharPlusSign            = 8,                            /* (`+')*/
  257.     kNumFmtCharMinusSign        = 9,                            /* (`-') */
  258.     kNumFmtCharThousandSep        = 10,                            /* (`,') */
  259.     kNumFmtCharFormatSeparator    = 11,                            /* (`;') */
  260.     kNumFmtCharEscape            = 12,                            /*  (`\') */
  261.     kNumFmtCharDecPoint            = 13,                            /* (`.') */
  262.     kNumFmtTextpePlus            = 14,                            /* (`E+') */
  263.     kNumFmtTextpeMinus            = 15,                            /* (`E-') */
  264.     kNumFmtTextMinusPlus        = 16,                            /* (`E') */
  265.     kNumFmtTextFirstRangeCurrencyForm = 17,                        /* (`Dollar') */
  266.     kNumFmtTextSecondRangeCurrencyForm = 18,                    /* (`Dollar(s)') */
  267.     kNumFmtTextPluralCurrency    = 19,                            /* (`Dollar(s)') */
  268.     kNumFmtTextfractionCurrency    = 20,                            /* (`cents)) */
  269.     kNumFmtTextCurrencyAbbreviated = 21,                        /* (`$') */
  270.     kNumFmtTextfractionCurrencyAbbreviated = 22,                /* (`¢') */
  271.     kNumFmtTextNegativePrefix    = 23,                            /* (`(`) */
  272.     kNumFmtTextNegativePostfix    = 24                            /* (`)') */
  273. };
  274.  
  275. typedef UInt32 CurrencyPosition;
  276.  
  277. enum {
  278.                                                                 /*CurrencyPosition*/
  279.     kAtTheBeginning                = 0,
  280.     kAtDecimalPointPosition        = 1,
  281.     kAtTheEnd                    = 2
  282. };
  283.  
  284. extern OSStatus CreateCustomNumberFormatLocaleObject(LocaleNumberFormatterObjectRef numberFormatterObject, LocaleNumberFormatterObjectRef *customNumberFormatterObject);
  285.  
  286. extern OSStatus DeleteCustomNumberFormatLocaleObject(LocaleNumberFormatterObjectRef customNumberFormatterObject);
  287.  
  288. extern OSStatus SetNumFmtTokenToParserToken(LocaleNumberFormatterObjectRef customNumberFormatterObject, NumberFormatterTokenID tokenID, BasicToken theToken);
  289.  
  290. extern OSStatus GetParserTokenFromNumFmtToken(LocaleNumberFormatterObjectRef customNumberFormatterObject, NumberFormatterTokenID tokenID, BasicToken *theToken);
  291.  
  292. extern OSStatus GetNumberFormatterTextFromToken(LocaleNumberFormatterObjectRef customNumberFormatterObject, NumberFormatterTokenID tokenID, TextObject theTextObject);
  293.  
  294. extern OSStatus SetNumFmtTokenToText(LocaleNumberFormatterObjectRef customNumberFormatterObject, NumberFormatterTokenID tokenID, ConstTextObject theTextObject);
  295.  
  296. extern OSStatus GetLocaleLongCurrencyPosition(LocaleNumberFormatterObjectRef customNumberFormatterObject, CurrencyPosition *position);
  297.  
  298. extern OSStatus SetLocaleLongCurrencyPosition(LocaleNumberFormatterObjectRef customNumberFormatterObject, CurrencyPosition position);
  299.  
  300. extern OSStatus GetLocaleAbbrevCurrencyPosition(LocaleNumberFormatterObjectRef customNumberFormatterObject, CurrencyPosition *position);
  301.  
  302. extern OSStatus SetLocaleAbbrevCurrencyPosition(LocaleNumberFormatterObjectRef customNumberFormatterObject, CurrencyPosition position);
  303.  
  304. extern OSStatus GetLocaleFirstRangeCurrency(LocaleNumberFormatterObjectRef customNumberFormatterObject, UInt32 *maxValueInRange);
  305.  
  306. extern OSStatus SetLocaleFirstRangeCurrency(LocaleNumberFormatterObjectRef customNumberFormatterObject, UInt32 maxValueInRange);
  307.  
  308. extern OSStatus GetLocaleSecondRangeCurrency(LocaleNumberFormatterObjectRef customNumberFormatterObject, UInt32 *maxValueInRange);
  309.  
  310. extern OSStatus SetLocaleSecondRangeCurrency(LocaleNumberFormatterObjectRef customNumberFormatterObject, UInt32 maxValueInRange);
  311.  
  312. extern OSStatus GetLocaleDigitText(LocaleNumberFormatterObjectRef customNumberFormatterObject, UInt8 theDigit, TextObject theTextObject);
  313.  
  314. extern OSStatus SetLocaleDigitText(LocaleNumberFormatterObjectRef customNumberFormatterObject, UInt8 theDigit, TextObject theTextObject);
  315.  
  316. #endif
  317.  
  318. #if PRAGMA_ALIGN_SUPPORTED
  319. #pragma options align=reset
  320. #endif
  321.  
  322. #if PRAGMA_IMPORT_SUPPORTED
  323. #pragma import off
  324. #endif
  325.  
  326. #ifdef __cplusplus
  327. }
  328. #endif
  329.  
  330. #endif /* __NUMBERFORMATTING__ */
  331.  
  332.